﻿//
// LastFMPhotoCrawlerSettings.cs: Settings for the LastFMPhotoCrawler project.
//
// Copyright 2010 Michael Goethe
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Linq;
using System.Text;
using System.Reflection;
using S9PalCommon;
using S9PalCommon.ArtistLibrary;

namespace LastFMPhotoCrawler
{
    /// <summary>
    /// Settings for the LastFMPhotoCrawler project.
    /// </summary>
    [Serializable]
    public sealed class LastFMPhotoCrawlerSettings : Settings
    {
        #region Fields

        private Artist lastFMPhotoCrawlerResumeArtist;
        private int lastFMPhotoCrawlerJPEGConversionQuality;
        private int artistPhotoDisplaySizeFactor;
        private int maxPhotosPerArtist;
        private int photosToDownloadPerPass;
        private int httpSleepTime;

        #endregion

        #region Constructors

        public LastFMPhotoCrawlerSettings() : base("LastFMPhotoCrawler.dat")
        {

        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the display size factor, which is multiplied by a coefficient to determine the photo display size.
        /// </summary>
        public int ArtistPhotoDisplaySizeFactor
        {
            get
            {
                return artistPhotoDisplaySizeFactor;
            }
            set
            {
                artistPhotoDisplaySizeFactor = value;
            }
        }

        /// <summary>
        /// Gets or sets the sleep time (in milliseconds) between the crawler's HTTP requests.
        /// </summary>
        public int HTTPSleepTime
        {
            get
            {
                return httpSleepTime;
            }
            set
            {
                if (value >= 2000)
                    httpSleepTime = value;
            }
        }

        /// <summary>
        /// Gets or sets the JPEG conversion quality, which is specified by a number between 1 and 100.
        /// </summary>
        public int JPEGConversionQuality
        {
            get
            {
                return lastFMPhotoCrawlerJPEGConversionQuality;
            }
            set
            {
                if (value > 0 && value <= 100)
                    lastFMPhotoCrawlerJPEGConversionQuality = value;
            }
        }

        /// <summary>
        /// Gets or sets the target maximum number of photos that the library should contain. When this number is reached, the crawler will no longer download new photos for the artist.
        /// </summary>
        public int MaxPhotosPerArtist
        {
            get
            {
                return maxPhotosPerArtist;
            }
            set
            {
                if (value > 0)
                    maxPhotosPerArtist = value;
            }

        }

        /// <summary>
        /// Gets or sets the target number of photos to download for each artist per crawler pass.
        /// </summary>
        public int PhotosToDownloadPerPass
        {
            get
            {
               return photosToDownloadPerPass;
            }
            set
            {
                if (value > 0)
                    photosToDownloadPerPass = value;
            }
        }

        /// <summary>
        /// Gets or sets the initial artist for when the crawler is resumed.
        /// </summary>
        public Artist ResumeArtist
        {
            get
            {
                return lastFMPhotoCrawlerResumeArtist;
            }
            set
            {
                lastFMPhotoCrawlerResumeArtist = value;
            }
        }

        #endregion

        #region Protected Methods

        /// <summary>
        /// Sets the settings to their defaults.
        /// </summary>
        protected override void OnDefault()
        {
            ArtistPhotoDisplaySizeFactor = 3;
            JPEGConversionQuality = 80;
            HTTPSleepTime = 3000;
            PhotosToDownloadPerPass = 10;
            MaxPhotosPerArtist = 20;
        }

        #endregion
    }
}
